home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / client / scripts / default.bind.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  8.6 KB  |  370 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. if ( isObject( moveMap ) )
  7.    moveMap.delete();
  8. new ActionMap(moveMap);
  9.  
  10.  
  11. //------------------------------------------------------------------------------
  12. // Non-remapable binds
  13. //------------------------------------------------------------------------------
  14.  
  15. function escapeFromGame()
  16. {
  17.    if ( $Server::ServerType $= "SinglePlayer" )
  18.       MessageBoxYesNo( "Quit Demo", "Exit from the demo?", "disconnect();", "");
  19.    else
  20.       MessageBoxYesNo( "Disconnect", "Disconnect from the server?", "disconnect();", "");
  21. }
  22.  
  23. moveMap.bindCmd(keyboard, "escape", "", "escapeFromGame();");
  24.  
  25. function showPlayerList(%val)
  26. {
  27.    if(%val)
  28.       PlayerListGui.toggle();
  29. }
  30.  
  31. moveMap.bind( keyboard, F2, showPlayerList );
  32.  
  33. //------------------------------------------------------------------------------
  34. // Movement Keys
  35. //------------------------------------------------------------------------------
  36.  
  37. $movementSpeed = 1; // m/s
  38.  
  39. function setSpeed(%speed)
  40. {
  41.    if(%speed)
  42.       $movementSpeed = %speed;
  43. }
  44.  
  45. function moveleft(%val)
  46. {
  47.    $mvLeftAction = %val;
  48. }
  49.  
  50. function moveright(%val)
  51. {
  52.    $mvRightAction = %val;
  53. }
  54.  
  55. function moveforward(%val)
  56. {
  57.    $mvForwardAction = %val;
  58. }
  59.  
  60. function movebackward(%val)
  61. {
  62.    $mvBackwardAction = %val;
  63. }
  64.  
  65. function moveup(%val)
  66. {
  67.    $mvUpAction = %val;
  68. }
  69.  
  70. function movedown(%val)
  71. {
  72.    $mvDownAction = %val;
  73. }
  74.  
  75. function turnLeft( %val )
  76. {
  77.    $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  78. }
  79.  
  80. function turnRight( %val )
  81. {
  82.    $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  83. }
  84.  
  85. function panUp( %val )
  86. {
  87.    $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  88. }
  89.  
  90. function panDown( %val )
  91. {
  92.    $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  93. }
  94.  
  95. function getMouseAdjustAmount(%val)
  96. {
  97.    // based on a default camera fov of 90'
  98.    return(%val * ($cameraFov / 90) * 0.01);
  99. }
  100.  
  101. function yaw(%val)
  102. {
  103.    $mvYaw += getMouseAdjustAmount(%val);
  104. }
  105.  
  106. function pitch(%val)
  107. {
  108.    $mvPitch += getMouseAdjustAmount(%val);
  109. }
  110.  
  111. function jump(%val)
  112. {
  113.    $mvTriggerCount2++;
  114. }
  115.  
  116. moveMap.bind( keyboard, a, moveleft );
  117. moveMap.bind( keyboard, d, moveright );
  118. moveMap.bind( keyboard, w, moveforward );
  119. moveMap.bind( keyboard, s, movebackward );
  120. moveMap.bind( keyboard, space, jump );
  121. moveMap.bind( mouse, xaxis, yaw );
  122. moveMap.bind( mouse, yaxis, pitch );
  123.  
  124.  
  125. //------------------------------------------------------------------------------
  126. // Mouse Trigger
  127. //------------------------------------------------------------------------------
  128.  
  129. function mouseFire(%val)
  130. {
  131.    $mvTriggerCount0++;
  132. }
  133.  
  134. function altTrigger(%val)
  135. {
  136.    $mvTriggerCount1++;
  137. }
  138.  
  139. moveMap.bind( mouse, button0, mouseFire );
  140. //moveMap.bind( mouse, button1, altTrigger );
  141.  
  142.  
  143. //------------------------------------------------------------------------------
  144. // Zoom and FOV functions
  145. //------------------------------------------------------------------------------
  146.  
  147. if($Pref::player::CurrentFOV $= "")
  148.    $Pref::player::CurrentFOV = 45;
  149.  
  150. function setZoomFOV(%val)
  151. {
  152.    if(%val)
  153.       toggleZoomFOV();
  154. }
  155.       
  156. function toggleZoom( %val )
  157. {
  158.    if ( %val )
  159.    {
  160.       $ZoomOn = true;
  161.       setFov( $Pref::player::CurrentFOV );
  162.    }
  163.    else
  164.    {
  165.       $ZoomOn = false;
  166.       setFov( $Pref::player::DefaultFov );
  167.    }
  168. }
  169.  
  170. moveMap.bind(keyboard, r, setZoomFOV);
  171. moveMap.bind(keyboard, e, toggleZoom);
  172.  
  173.  
  174. //------------------------------------------------------------------------------
  175. // Camera & View functions
  176. //------------------------------------------------------------------------------
  177.  
  178. function toggleFreeLook( %val )
  179. {
  180.    if ( %val )
  181.       $mvFreeLook = true;
  182.    else
  183.       $mvFreeLook = false;
  184. }
  185.  
  186. $firstPerson = true;
  187. function toggleFirstPerson(%val)
  188. {
  189.    if (%val)
  190.    {
  191.       $firstPerson = !$firstPerson;
  192.       ServerConnection.setFirstPerson($firstPerson);
  193.    }
  194. }
  195.  
  196. function toggleCamera(%val)
  197. {
  198.    if (%val)
  199.       commandToServer('ToggleCamera');
  200. }
  201.  
  202. moveMap.bind( keyboard, z, toggleFreeLook );
  203. moveMap.bind(keyboard, tab, toggleFirstPerson );
  204. moveMap.bind(keyboard, "alt c", toggleCamera);
  205.  
  206.  
  207. //------------------------------------------------------------------------------
  208. // Misc. Player stuff
  209. //------------------------------------------------------------------------------
  210.  
  211. function celebrationWave(%val)
  212. {
  213.    if(%val)
  214.       commandToServer('playCel', "wave");
  215. }
  216.  
  217. function celebrationSalute(%val)
  218. {
  219.    if(%val)
  220.       commandToServer('playCel', "salute");
  221. }
  222.  
  223. function suicide(%val)
  224. {
  225.    if(%val)
  226.       commandToServer('suicide');
  227. }
  228.  
  229. moveMap.bind(keyboard, "ctrl w", celebrationWave);
  230. moveMap.bind(keyboard, "ctrl s", celebrationSalute);
  231. moveMap.bind(keyboard, "ctrl k", suicide);
  232.  
  233. //------------------------------------------------------------------------------
  234. // Item manipulation
  235. //------------------------------------------------------------------------------
  236.  
  237. moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"Crossbow\");", "");
  238.  
  239. //------------------------------------------------------------------------------
  240. // Message HUD functions
  241. //------------------------------------------------------------------------------
  242.  
  243. function pageMessageHudUp( %val )
  244. {
  245.    if ( %val )
  246.       pageUpMessageHud();
  247. }
  248.  
  249. function pageMessageHudDown( %val )
  250. {
  251.    if ( %val )
  252.       pageDownMessageHud();
  253. }
  254.  
  255. function resizeMessageHud( %val )
  256. {
  257.    if ( %val )
  258.       cycleMessageHudSize();
  259. }
  260.  
  261. moveMap.bind(keyboard, u, toggleMessageHud );
  262. //moveMap.bind(keyboard, y, teamMessageHud );
  263. moveMap.bind(keyboard, "pageUp", pageMessageHudUp );
  264. moveMap.bind(keyboard, "pageDown", pageMessageHudDown );
  265. moveMap.bind(keyboard, "p", resizeMessageHud );
  266.  
  267.  
  268. //------------------------------------------------------------------------------
  269. // Demo recording functions
  270. //------------------------------------------------------------------------------
  271.  
  272. function startRecordingDemo( %val )
  273. {
  274. //    if ( %val )
  275. //       beginDemoRecord();
  276.    error( "** This function has temporarily been disabled! **" );
  277. }
  278.  
  279. function stopRecordingDemo( %val )
  280. {
  281. //    if ( %val )
  282. //       stopRecord();
  283.    error( "** This function has temporarily been disabled! **" );
  284. }
  285.  
  286. //moveMap.bind( keyboard, F3, startRecordingDemo );
  287. //moveMap.bind( keyboard, F4, stopRecordingDemo );
  288.  
  289.  
  290. //------------------------------------------------------------------------------
  291. // Helper Functions
  292. //------------------------------------------------------------------------------
  293.  
  294. function dropCameraAtPlayer(%val)
  295. {
  296.    if (%val) 
  297.       commandToServer('dropCameraAtPlayer');
  298.    
  299. }
  300.  
  301. function dropPlayerAtCamera(%val)
  302. {
  303.    if (%val)
  304.       commandToServer('DropPlayerAtCamera');
  305. }
  306.  
  307. moveMap.bind(keyboard, "F8", dropCameraAtPlayer);
  308. moveMap.bind(keyboard, "F7", dropPlayerAtCamera);
  309.  
  310.  
  311. function bringUpOptions(%val)
  312. {
  313.    if(%val)
  314.       Canvas.pushDialog(OptionsDlg);
  315. }
  316.  
  317. moveMap.bind(keyboard, "ctrl o", bringUpOptions);
  318.  
  319. //------------------------------------------------------------------------------
  320. // Dubuging Functions
  321. //------------------------------------------------------------------------------
  322.  
  323. $MFDebugRenderMode = 0;
  324. function cycleDebugRenderMode(%val)
  325. {
  326.    if (!%val)
  327.       return;
  328.  
  329.    if (getBuildString() $= "Debug")
  330.    {
  331.       if($MFDebugRenderMode == 0)
  332.       {
  333.          // Outline mode, including fonts so no stats
  334.          $MFDebugRenderMode = 1;
  335.          GLEnableOutline(true);
  336.       }
  337.       else if ($MFDebugRenderMode == 1)
  338.       {
  339.          // Interior debug mode
  340.          $MFDebugRenderMode = 2;
  341.          GLEnableOutline(false);
  342.          setInteriorRenderMode(7);
  343.          showInterior();
  344.       }
  345.       else if ($MFDebugRenderMode == 2)
  346.       {
  347.          // Back to normal
  348.          $MFDebugRenderMode = 0;
  349.          setInteriorRenderMode(0);
  350.          GLEnableOutline(false);
  351.          show();
  352.       }
  353.    }
  354.    else
  355.    {
  356.       echo("Debug render modes only available when running a Debug build.");
  357.    }
  358. }
  359.  
  360. GlobalActionMap.bind(keyboard, "F9", cycleDebugRenderMode);
  361.  
  362.  
  363. //------------------------------------------------------------------------------
  364. // Misc.
  365. //------------------------------------------------------------------------------
  366.  
  367. GlobalActionMap.bind(keyboard, "tilde", toggleConsole);
  368. GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");
  369. GlobalActionMap.bindCmd(keyboard, "F1", "", "contextHelp();");
  370.